//
//  YSZBaseTableViewController.swift
//  swiftweibo6
//
//  Created by ysz on 15/11/23.
//  Copyright © 2015年 user. All rights reserved.
//

import UIKit

class YSZBaseTableViewController: UITableViewController
{
    var userLogin = YSZUserAccount.userLogin
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
  
    
    //判断是那个页面
    private func setupVisitorView()
    {
        let visitorView = YSZMainView()
        view = visitorView
        if self is YSZHomeViewController
        {
            visitorView.startRotationAnimation()
            //监听进入后台时
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            //监听应用进入前台时
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeAction", name: UIApplicationDidBecomeActiveNotification, object: nil)
        }
        else if self is YSZMessageViewController
        {
            visitorView.setUpInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }
        else if self is YSZProfileViewController
        {
            visitorView.setUpInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        else if self is YSZDiscoverViewController
        {
            visitorView.setUpInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }
        visitorView.visitorDelegate = self
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLogin")
        
    }
    //应用进入后台时调用
    func didEnterBackground()
    {
        (view as! YSZMainView).pauseAnimation()
    }
    //应用进入前台时调用
    func didBecomeAction()
    {
        (view as! YSZMainView).resumeAnimation()
    }
}
//  扩展，实现协议
//  扩展，和oc category类似 extension可以实现协议，方便代码管理统一管理
extension YSZBaseTableViewController : YSZMainViewDelegate
{
    func visitorViewRegister()
    {
        print(__FUNCTION__)
    }
    func visitorViewLogin()
    {
//        print(__FUNCTION__)
        //创建授权界面
        let oauthVC=YSZOauthViewController()
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
        
    }
}
















